package common.util;

import java.io.File;
import android.content.Context;
import android.os.Environment;

public class SdCardHelper {

	public static final boolean isWriteable(Context context) {
		return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
	}

	public static final boolean isReadable(Context context) {
		return Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState()) || isWriteable(context);
	}

	public static final long getUsableSpace(Context context) {
		if (isReadable(context)) {
			return Environment.getExternalStorageDirectory().getUsableSpace();
		}
		return -1;
	}

	public static final boolean isWriteable(Context context, File[] files) {
		long fileSize = 0;
		for (File f : files) {
			fileSize += f.length();
		}

		return fileSize <= getUsableSpace(context);
	}
}
